/**
 * Created by superman on 17/2/16.
 * http配置
 */

import axios from 'axios'
import store from './store/store'
import * as types from './store/types'
import router from './router'
import Qs from 'qs'

// axios 配置
axios.defaults.timeout = 5000;
// axios.defaults.baseURL = 'http://192.168.1.144:3000';
// axios.defaults.baseURL = 'http://192.168.1.143:8085/pms';//俊涛测试
axios.defaults.baseURL = 'http://192.168.0.17:8082/pms';//测试服务器
// axios.defaults.baseURL = 'http://192.168.1.148:8081/pms';//成苍测试
// axios.defaults.baseURL = 'http://192.168.1.135:8080/mongo/api';//肥仔测试
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
// axios.defaults.withCredentials = true;
axios.defaults.transformRequest = [function (data) {
    data = Qs.stringify(data);
    return data;
}];

// http request 拦截器
// axios.interceptors.request.use(
//     config => {
//         if (localStorage.token) {
//             config.headers.Authorization =  'Bearer ' + localStorage.token;
//         }
//         return config;
//     },
//     err => {
//         return Promise.reject(err);
//     });

// http response 拦截器
// axios.interceptors.response.use(
//     response => {
//         return response;
//     },
//     error => {
//         if (error.response) {
//             switch (error.response.status) {
//                 case 401:
//                     // 401 清除token信息并跳转到登录页面
//                     store.commit(types.LOGOUT);
//                     router.replace({
//                         path: 'login',
//                         query: {redirect: router.currentRoute.fullPath}
//                     })
//             }
//         }
//         // console.log(JSON.stringify(error));//console : Error: Request failed with status code 402
//         return Promise.reject(error)
//     });

export default axios;
